package exam.controller;

import exam.bean.MarkPoints;
import exam.service.IMarkPointService;
import exam.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController()
@RequestMapping("/MarkPoints")
public class MarkPointController {
    @Autowired
    IMarkPointService markPointService;
    @PreAuthorize("hasAuthority('sys:map')")

    @ResponseBody
    @GetMapping("/MarkPoint")
    //@RequestMapping(value = "/MarkPoint",method = {RequestMethod.POST,RequestMethod.GET})
    public Msg markPoint(){
        return Msg.success().add("markPoint",markPointService.selectInfo());
    }

    @PreAuthorize("hasAuthority('sys:map:deatil')")
    @ResponseBody
    @GetMapping("/detail")
    public Msg detail(@RequestParam(value="id") int id){
        return Msg.success().add("markPoint",markPointService.selectInfoSingle(id));
    }

    @PreAuthorize("hasAuthority('sys:map:delete')")
    @ResponseBody
    @GetMapping("/delete")
    public Msg delete (@RequestParam(value="id") int id){
        boolean re =  markPointService.deleteInfo(id) > 0 ;
        return Msg.success().setMessage(re ? "删除成功":"删除失败");
    }

    @PreAuthorize("hasAuthority('sys:map:add')")
    @PostMapping("/add")
    public Msg add(@RequestBody MarkPoints markPoints){
        boolean re = markPointService.insertInfo(markPoints) > 0 ;
        return Msg.success().setMessage(re ? "添加成功":"添加失败");
    }

    @PreAuthorize("hasAuthority('sys:map:update')")
    @ResponseBody
    @PostMapping("/upData")
    public Msg update(@RequestBody MarkPoints markPoints){
        boolean re = markPointService.updateInfo(markPoints) > 0;
        return Msg.success().setMessage(re ? "更新成功":"更新失败");
    }

}
